package com.novartis.nims.imagedc.application;

import java.io.InputStream;
import java.util.Properties;

import javax.swing.SwingUtilities;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

import com.novartis.nims.imagedc.configuration.ConfigurationHelper;
import com.novartis.nims.imagedc.logic.RuleSet;
import com.novartis.nims.imagedc.logic.ScanManager;

public class Application {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Logger.getRootLogger().setLevel(Level.DEBUG);
		
		ApplicationView view = new ApplicationView();

		try {
			Serializer serializer = new Persister();
			RuleSet rules = serializer.read(RuleSet.class, ConfigurationHelper.class.getResourceAsStream("scan-id-rules.xml"));
			
			InputStream conformanceSpec = ConfigurationHelper.class.getResourceAsStream("generic.decs.xml");
			InputStream transformation = ConfigurationHelper.class.getResourceAsStream("decs2mirc.xslt");
			Properties deidentificationRules = ConfigurationHelper.parseDicomConformanceSpec(conformanceSpec, transformation);
			
			ScanManager scanManager = new ScanManager();
			scanManager.setRules(rules);
			scanManager.setDeidentificationProperties(deidentificationRules);
			scanManager.setSubmissionUrl(ConfigurationHelper.getScanServiceUrl());
			ApplicationController appController = new ApplicationController(view, scanManager);
			scanManager.registerWorkflowController(appController);
			view.setController(appController);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		SwingUtilities.invokeLater(view);
	}

}
